package cbbx_sm.utils;

import java.util.ArrayList;

import cbbx_sm.parser.BoundingBox;

public class BoundingBoxKMeansClustering extends KMeansClustering{

	@Override
	public double approximateDist(Object a, Object b) {
		return dist(a, b);
	}

	@Override
	public Object cent(ArrayList<Object> cluster) {
		float x = 0;
		float y = 0;
		
		for (Object o: cluster){
			BoundingBox boxo = (BoundingBox)o;
			x+=boxo.getCenterX();
			y+=boxo.getCenterY();
		}
		
		return new BoundingBox(Math.round(x/cluster.size()),Math.round(y/cluster.size()), Math.round(x/cluster.size()),Math.round(y/cluster.size()));
	}

	@Override
	public double dist(Object a, Object b) {
		BoundingBox boxa = (BoundingBox)a;
		BoundingBox boxb = (BoundingBox)b;
		
		return Utility.computeBBoxCenterDistance(boxa, boxb);
	}

}
